
public class Bid {

	private String m_contractString;
	private boolean m_contractAccepted;
	private Player m_player;
	//public short m_contractID;
	private static char[] alphabet;
	private int m_playerSenderID;
	
	public Bid(String contractString, Player player)
	{
		m_contractString = contractString;
		m_player = player;
		alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789()".toCharArray();

	}
	
	//Returns 0 if no type exists
	/*
	public static short GetContractID(String contractString)
	{
		
		short num2=-1;
		short num1=-1;
		for(short j = 0; j < alphabet.length; ++j)
		{
			if(alphabet[j] == contractString.charAt(0))
				num2 = j;
			if(alphabet[j] == contractString.charAt(1))
				num1 = j;
		}	
		
		short contractID = (short) ( (num2<<6) + num1);
		
		return contractID;
		
	}
	*/
	
	//Returns 0 if no type exists
	public static int GetContractType(String contractString)
	{
		
		switch (contractString.charAt(6) )
		{
		case 'a':
			return 1;
		case 'd':
			return 2;
		
		}

		return 0;
	}
	
	public boolean ContractAccepted()
	{
		return m_contractAccepted;
	}
	
	public boolean ProcessContract()
	{
		//Process contract here
		if( GetContractType(m_contractString) == 0) //Test: only accepts defense contracts
		{
			m_contractAccepted = true;
			return true;
		}
		else
		{
			m_contractAccepted = false; 
			return false;
			
		}
		
	}
	
	//TODO: Cambiar este booleano a un tipo de dato con informacion y costo de 'bid'
	public void ReplyToContract(boolean answer)
	{
		//Send reply to original contract author with data and cost
		if(answer == true)
		{
			m_player.say(String.valueOf( m_playerSenderID ) + "21" );
		}
		else
		{
			m_player.say(String.valueOf( m_playerSenderID ) + "20" );
			
		}
	
	}
}
